package com.alexatguigu.juc042202.Controller;

import com.alexatguigu.juc042202.Service.CinemaService;
import com.alexatguigu.juc042202.entity.MovieSeat;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/alex008/cinema")
public class CinemaController {
    
    @Autowired
    private CinemaService cinemaService;
    
    // 查看所有座位
    @GetMapping("/seats")
    public List<MovieSeat> getAllSeats() {
        return cinemaService.getAllSeats();
    }
    
    // Lock方式订座
    @GetMapping("/book-lock")
    public String bookSeatWithLock(@RequestParam Integer seatId, @RequestParam String userName) {
        return cinemaService.bookSeatWithLock(seatId, userName);
    }
    
    // Synchronized方式订座
    @GetMapping("/book-sync")
    public String bookSeatWithSync(@RequestParam Integer seatId, @RequestParam String userName) {
        return cinemaService.bookSeatWithSync(seatId, userName);
    }
}